<?php

require 'init.php';

Logger::add($_REQUEST);
if($_POST){
  $task =  $_POST['task'];
  $ds = new Manage_DataService_Navigation();
  $id =  (int)$_POST['id'];
  if($task == 'move'){
    $parent_id =  (int)$_POST['parent_id'];
    $prev_id =  (int)$_POST['prev_id'];
    $ds->moveNode($id,$parent_id, $prev_id);
  }else if($task = 'remove'){
    $ds->removeNode($id);
  }  
}
$sql = "
  SELECT node.*
  FROM core_nav_item node
  where nav_id = 6
  ORDER BY node.lft;
";

$db = Db::factory();
$items =  $db->fetchAll($sql);
?>
<table border="1">
<?php
foreach($items as $item){
  echo sprintf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>', $item['id'], $item['lft'], $item['rgt'], $item['label'], $item['depth']);
}?>
</table>
<br />
<form method="post">
  <label for="id">id: </label><input name="id" type="text"/><br />
  <label for="parent_id">parent id: </label><input type="text" name="parent_id" /><br />
  <label for="prev_id">prev id: </label><input type="text" name="prev_id" /><br />
  <input type="submit" name="task" value="move"/>
  <input type="submit" name="task" value="remove"/>
</form>